﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using OpenIddict.Validation.AspNetCore;
using WT.OpenIddict.Application.Contracts.OpenIddictApplication;
using WT.OpenIddict.Application.Contracts.OpenIddictApplication.Dto;

namespace WT.OpenIddict.WebApi.Controllers;

[Route("api/openid-dict-application")]
[Authorize(AuthenticationSchemes = OpenIddictValidationAspNetCoreDefaults.AuthenticationScheme)]
public class OpenIddictApplicationController : ControllerBase, IOpenIddictApplicationAppService
{
    private readonly IOpenIddictApplicationAppService _openIddictApplicationAppService;

    public OpenIddictApplicationController(IOpenIddictApplicationAppService openIddictApplicationAppService)
    {
        _openIddictApplicationAppService = openIddictApplicationAppService;
    }

    [HttpGet]
    [Authorize(AuthenticationSchemes = "CustomCookie")]
    [Route("by-client-id/{clientId}")]
    public Task<OpenIddictApplicationDto> GetClientByClientId(string clientId)
    {
        return _openIddictApplicationAppService.GetClientByClientId(clientId);
    }
}